package io.renren.modules.workflow.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * @Desc 流程业务工具类
 * @Author landlord
 * @Date 2021/7/17 15:47
 */
public class ActBusBusinessUtils {
    private static String BUSINESSTYPE_TRANSFER = "transfer";
    private static String BUSINESSTYPE_USING = "using";
    private static String BUSINESSTYPE_DESTROY = "destroy";
    private static String BUSINESSTYPE_IDENTIFICATION = "identification";
    //定义流程标题
   public static String setWordFlowTitle(Map<String,Object> params){
       //默认规则定义 单位名称 的 姓名 提交了 业务流程名称(例如 档案移交单、档案利用单、档案销毁单、档案鉴定处置单)
       String businessType = params.get("businessType").toString();
       String businessTypeName = "";
       if(businessType.equals(BUSINESSTYPE_TRANSFER)){
           businessTypeName = "档案移交申请单";
       }else if(businessType.equals(BUSINESSTYPE_USING)){
           businessTypeName = "档案利用申请单";
       }else if(businessType.equals(BUSINESSTYPE_DESTROY)){
           businessTypeName = "档案销毁申请单";
       }else if(businessType.equals(BUSINESSTYPE_IDENTIFICATION)){
           businessTypeName = "档案鉴定处置申请单";
       }

       return " 提交了 "+businessTypeName;
   }


   //解析流程表单json
    public static Map<String,Object> parseWorkFlowFormJson(String jsonStr) throws Exception {
        JSONArray jsonForm = null;
        Map<String,Object> vars = new HashMap<>();
        try {
            jsonForm = JSONArray.parseArray(jsonStr);
        } catch (Exception e) {
            throw new Exception("表单格式不正确");
        }
        //解析JSON 获取字段属性
        if (jsonForm != null && jsonForm.size() > 0) {
            for (int i = 0; i < jsonForm.size(); i++) {
                JSONObject jsonVal = jsonForm.getJSONObject(i);
                vars.put(jsonVal.getString("vModel"),jsonVal.getString("__value"));
            }
        }
        return vars;
    }
}
